package Controller.Employee;

import MyException.MyException;
import Service.EmployeeService;
import Service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;

@WebServlet(name = "selectAllEmployee", value = "/selectAllEmployee")
public class SelectAllEmployee extends HttpServlet {
    private EmployeeService employeeService = new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //转码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //获取所有员工信息
        String name = request.getParameter("name");
        String idcard = request.getParameter("idcard");
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String status = request.getParameter("status");
        try{
            Map<String, Object> map = employeeService.selectAllEmployee(name, idcard, startDate, endDate, status);
            request.setAttribute("map", map);
            request.getRequestDispatcher("/ListEmployee.jsp").forward(request, response);
        }catch (SQLException e){
            e.printStackTrace();
        }catch (MyException e){
            System.out.println("查询错误");
        }

    }
}
